//
//  BIDEvaluateView.m
//  HJGJCommunity
//
//  Created by mal on 2017/6/9.
//  Copyright © 2017年 mal. All rights reserved.
//

#import "BIDEvaluateView.h"

@interface BIDEvaluateView()
{
    NSUInteger _score;
    NSArray *_btnArr;
}
@end

@implementation BIDEvaluateView

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if(self)
    {
        NSString *className = NSStringFromClass([self class]);
        self.view = [[[NSBundle mainBundle] loadNibNamed:className owner:self options:nil] firstObject];
        [self addSubview:self.view];
        return self;
    }
    return nil;
}

- (IBAction)starBtnHandler:(id)sender
{
    _btnArr = @[_oneBtn, _twoBtn, _threeBtn, _fourBtn, _fiveBtn];
    _score = 0;
    UIButton *btn = (UIButton *)sender;
    NSUInteger tag = btn.tag;
    if(btn.isSelected)
    {
        _score = tag-1;
        //置为未被选中
        btn.selected = NO;
        for(UIButton *tempBtn in _btnArr)
        {
            if(tempBtn.tag < tag)
            {
                tempBtn.selected = YES;
                [tempBtn setBackgroundImage:[UIImage imageNamed:@"star_highlight.png"] forState:UIControlStateNormal];
            }
            else
            {
                tempBtn.selected = NO;
                [tempBtn setBackgroundImage:[UIImage imageNamed:@"star_normal.png"] forState:UIControlStateNormal];
            }
        }
    }
    else
    {
        _score = tag;
        //置为已选中
        btn.selected = YES;
        for(UIButton *tempBtn in _btnArr)
        {
            if(tempBtn.tag > tag)
            {
                tempBtn.selected = NO;
                [tempBtn setBackgroundImage:[UIImage imageNamed:@"star_normal.png"] forState:UIControlStateNormal];
            }
            else
            {
                tempBtn.selected = YES;
                [tempBtn setBackgroundImage:[UIImage imageNamed:@"star_highlight.png"] forState:UIControlStateNormal];
            }
        }
    }
}

- (NSUInteger)getScore
{
    return _score;
}

@end
